#include<vector>
#include<string>

using namespace std;

class Solution {
public:
    string countAndSay(int n) {
        vector<string> v(n);
        v[0] += '1';
        for (int i = 0; i < n - 1; i++)
        {
            int left = 0;
            int right = 0;
            while (left < v[i].size() && right < v[i].size())
            {
                while (right < v[i].size() && v[i][right] == v[i][left])
                {
                    right++;
                }
                char count = '0' + (right - left);
                char tem = v[i][left];
                v[i + 1].push_back(count);
                v[i + 1].push_back(tem);
                left = right;
            }
        }
        return v.back();
    }
};

int main()
{
    Solution s;
    s.countAndSay(4);
    return 0;
}